package com.kerbores.blog.service.impl;

import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;

import com.kerbores.blog.service.IChartsService;
import com.kerbores.utils.common.DateUtils;
import com.kerbores.utils.db.SqlActuator;

/**
 * @author Kerbores<br>
 *
 *         create at 2014年11月9日 下午11:15:54
 */
@IocBean(name = "chartsService")
public class ChartsServiceImpl implements IChartsService {

	@Inject
	private Dao dao;
	@Inject
	private PropertiesProxy sqls;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.kerbores.blog.service.IChartsService#run()
	 */
	@Override
	public Object run() {
		NutMap data = new NutMap();
		data.put("os", SqlActuator.runReport(sqls.get("os"), dao));
		data.put("browser", SqlActuator.runReport(sqls.get("browser"), dao));
		Sql pvSql = Sqls.create(sqls.get("pv"));
		pvSql.params().set("start", DateUtils.getDayStart()).set("end", DateUtils.addDays(DateUtils.getDayStart(), 1));
		data.put("pv", SqlActuator.runReport(pvSql, dao));
		data.put("ips", SqlActuator.runReport(sqls.get("ips"), dao));
		return data;
	}
}
